package com.wh.message.Controller;

import com.wh.message.Model.MessageInfo;
import com.wh.message.Service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @RequestMapping("/publish")
    public boolean publish(MessageInfo messageInfo) {
        if (!StringUtils.hasLength(messageInfo.getFrom()) ||
                !StringUtils.hasLength(messageInfo.getSay()) ||
                !StringUtils.hasLength(messageInfo.getTo())) {
            return false;
        }
        Integer result = messageService.publishMessage(messageInfo);
        if (result < 0) {
            return false;
        }
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageService.getListService();
    }
}
